import fetcher from "../apis/Fetcher";
import {Page, Pageable} from "../utils/Page";
import {NumberIdAndName} from "../types/BasicModels";

export interface QueryFactoriesRequest {
    name?: string
    address?:string
    contact?:string
    disable?:boolean
}

export function queryFactories(queryFactoriesRequest: QueryFactoriesRequest, pageable: Pageable) {
    return fetcher.get<Page<QueryFactoriesResponse>>("/factories", {...queryFactoriesRequest, ...pageable.toRequestParams()})
}

export interface QueryFactoriesResponse{
    id:number
    name:string
    address:string
    contact:string
    goodsAmount:number
    disable:boolean
}

export interface CreateFactoryRequest{
    name:string
    address?:string
    contact?:string
}

export function createFactory(createFactoryRequest:CreateFactoryRequest){
    return fetcher.post<number>("factories",{},createFactoryRequest)
}

export function updateFactory(id:number,createFactoryRequest:CreateFactoryRequest){
    return fetcher.put(`factories/${id}`,{},createFactoryRequest)
}

export function getAllFactory(){
    return fetcher.get<Array<NumberIdAndName>>("factories")
}

export function enableFactory(id:number){
    return fetcher.patch(`factories/${id}/enable`)
}

export function disableFactory(id:number){
    return fetcher.patch(`factories/${id}/disable`)
}